package com.ruoyi.project.bajiaostar.user;


import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.bajiaostar.tUserAddress.domain.TUserAddress;
import com.ruoyi.project.bajiaostar.tUserAddress.service.ITUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 用户端绑定地址
 */
@RestController
@RequestMapping("/nt/address")
public class WebUserAddressController extends BaseController {

    @Autowired
    private ITUserAddressService tUserAddressService;


    /**
     * 查询用户收货地址列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody TUserAddress tUserAddress) throws Exception {
        tUserAddress.setUserId(getAppUserId());
        tUserAddress.setAddressFlag(0);
        startPage();
        List<TUserAddress> list = tUserAddressService.selectTUserAddressList(tUserAddress);
        return getDataTable(list);
    }


    /**
     * 新增保存用户收货地址
     */
    @Log(title = "用户收货地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody TUserAddress tUserAddress) throws Exception {
        tUserAddress.setUserId(getAppUserId());
        return toAjax(tUserAddressService.insertTUserAddress(tUserAddress));
    }


    /**
     * 修改用户收货地址
     */
    @GetMapping("/edit/{id}")
    public AjaxResult edit(@PathVariable("id") Long id)
    {
        TUserAddress tUserAddress = tUserAddressService.selectTUserAddressById(id);
        return AjaxResult.success(tUserAddress);
    }

    /**
     * 修改保存用户收货地址
     */
    @Log(title = "用户收货地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody TUserAddress tUserAddress)
    {
        return toAjax(tUserAddressService.updateTUserAddress(tUserAddress));
    }
}
